<template>
  <div>
    <el-form :inline="true">
      <el-form-item>
        <el-input v-model="query.keyWord" placeholder="考试名称" clearable></el-input>
      </el-form-item>

      <el-form-item>
        <el-button
          v-if="hasPermission(['system:exam:list'])"
          @click="searchExamInfo"
          icon="el-icon-search" type="primary">查询
        </el-button>
      </el-form-item>
    </el-form>

    <el-table
      :data="examInfoList"
      border
      v-loading="loading"
      style="width: 100%;">

      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>

      <el-table-column
        prop="name"
        align="center"
        min-width="200"
        label="考试名称">
      </el-table-column>

      <el-table-column
        prop="examNumber"
        align="center"
        label="参考人数">
      </el-table-column>

      <el-table-column
        prop="avgSource"
        align="center"
        label="平均分">
      </el-table-column>

      <el-table-column
        prop="mark"
        align="center"
        label="总分">
      </el-table-column>

      <el-table-column
        header-align="center"
        align="center"
        min-width="210"
        label="操作">
        <template slot-scope="scope">
          <el-button
            size="small"
            @click="examDetail(scope.row)"
            type="warning">分析报告
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      background
      @size-change="changeSize"
      @current-change="changePage"
      :current-page="currentPage"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      :total="totalCount"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
import {examTypeDict, examTypeList} from '@/api/dict.js'

export default {
  name: 'examReport',
  data () {
    return {
      examTypeDict: examTypeDict,
      examTypeList: examTypeList,
      query: {

        keyWord: '',
        subjectId: ''
      },
      subjectList: [],
      examInfoList: [],
      loading: true,

      currentPage: 1,
      pageSize: 10,
      totalCount: 0
    }
  },

  watch: {},

  mounted () {
    this.getExamReportList()
  },

  methods: {

    searchExamInfo () {
      this.currentPage = 1
      this.loading = true
      this.getExamReportList()
    },

    changeSize (val) {
      this.pageSize = val
      this.currentPage = 1
      this.loading = true
      this.getExamReportList()
    },

    changePage (val) {
      this.currentPage = val
      this.loading = true
      this.getExamReportList()
    },

    getExamReportList () {
      this.axios.get(this.$http.httpUrl('/system/exam/getExamReportList'), {
        params: {
          pageNumber: this.currentPage,
          pageSize: this.pageSize,
          correctFlag: 1,
          testPaperInfoName: this.query.keyWord,

          subjectId: this.query.subjectId
        }
      }).then(response => {
        this.examInfoList = response.data.data.dataList
        this.totalCount = response.data.data.total
        this.loading = false
      })
    },

    examDetail (testPaperInfo) {
      this.$store.commit('map/updateTestPaperInfo', testPaperInfo)
      this.$router.push('examReportDetail')
    }
  },

  filters: {}
}
</script>

<style scoped>

</style>
